import regeneratorRuntime from '../../resource/libs/runtime'
import service from '../../common/service'

let app = getApp()

Page({
  data: {
    origin_money: 0,
    km: 0,
    km_money: 0,
    time: 0,
    time_money: 0,
    interval: [ // 不同时间段的价格表
      {
        time_begin: '00:00:00',
        time_end: '00:00:00',
        price: 18
      }
    ],
    start: [ // 不同里程的价格表
      {
        distance: 0,
        price: 0
      },
      {
        distance: 0,
        price: 0
      }
    ],
    wait: { // 等待时长的价格表
      free: 0,
      price: 0
    }
  },

  async onLoad () {
    let {
      origin_money,
      km,
      km_money,
      time,
      time_money,
      interval,
      start,
      wait
    } = app.global_data
    if (!start.length) {
      wx.showLoading({
        title: '数据加载中'
      })
      let res = await service.getPromise('SystemPrice/initPrice/mini')
      wx.hideLoading()
      if (typeof res === 'number') { return }
      if (res) {
        interval = res.data.interval
        start = res.data.start
        wait = res.data.wait
        app.updateGlobalData({ interval, start, wait })
      }
    }
    this.setData({
      origin_money,
      km,
      km_money,
      time,
      time_money,
      interval,
      start,
      wait
    })
  }
})